package com.tongtailian.www.stir.bean;

import com.tongtailian.www.stir.utils.CharUtils;
import com.tongtailian.www.stir.utils.LogUtil;
import com.tongtailian.www.stir.utils.ToastUtils;

/**
 * @author liuml
 * @explain
 * @time 2020/10/11 12:53
 */
public class ConfigDataFram extends BaseDataFram {

    private String leftName;//左边的标题 样品名称 研磨时间 等等
    private String value;//值
    private String value2;//值 第二个值
    private String unit;//单位 秒
    private String isCheckd;//复选框是否选中;
    private boolean isEdit;//是否可编辑

    private int styleType; //有几种类型 1 一个edittext 2 两个edittext 3 只有一个选择框
    private String cGroupName;
    private String hexGroupName;
//    char cGroupName[16];

    // 工作参数 4字节
    int iTimeWork;     // 时间 均质工作 均值时间
    int iTimeWater;   // 清水清洗时间
    int iTimeClear;   // 烘干清洗时间
    int iTimeSuper;   // 超声波清洗时间

    //两字节
    int cCountWork;   // 均质位甩干次数 研磨位  研磨位分段下降
    int cCountWater;   // 清水位甩干次数
    int cCountClear;   // 烘干位甩干次数 烘干清洗次数 对应 添加洗涤剂 1添加 0 不添加
    int cCountSuper;   // 超声位清洗甩干次数

    // 清洗槽液体排出时间
    int iInWater;     // 加入时间 清水槽
    int iInClear;     // 加入时间 洗剂槽  加入洗涤剂到超声波槽
    int iInSuper;     // 加入时间 超声槽  超声波槽清洗剂加入时间

    int iOutWater;     // 时间 排出 清水槽
    int iOutClear;     // 时间 排出 洗剂槽
    int iOutSuper;     // 时间 排出 超声槽

    // 选择 2字节
    int cClrSelect;     // 清洗位置选择 bit0 = 1，清水清洗位选择。  7是有烘干  5 是无烘干
    //    bit1 = 1，烘干清洗位选择。
//    Bit2 = 1，超声波清洗位选择。必选
//    bit3~7 保留
    int cClrMode;      // 工作位刀头浮动。0=不浮动。
    int cRFUA;      // 保留 字


    // 全局功能
//    unsigned char cRFUA[2];    // 保留
    //4 字节
    int iMotorSpeed;   // 均质工作电机速度  均质工作下降时电机转速   转刀转速
    int iMotorBackSpeed;  // 均质工作电机返回速度
    int iWorkFlwTime;  // 工作位浮动间隔时间  转刀浮动  未选中 则为0
    int iSuperMotT;   // 超声位电机转动时间
    int iSuperFlwT;   // 超声位浮动间隔时间
    int iRFUB;

    public String getValue2() {
        return value2;
    }

    public void setValue2(String value2) {
        this.value2 = value2;
    }

    public String getIsCheckd() {
        return isCheckd;
    }

    public void setIsCheckd(String isCheckd) {
        this.isCheckd = isCheckd;
    }

    public String getLeftName() {
        return leftName;
    }

    public void setLeftName(String leftName) {
        this.leftName = leftName;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }
//     char cRFU[13];

    /**
     * @param param 共有 8套 00至 07  是8组
     * @param data
     */
    public ConfigDataFram(String param, String data) {
        this.type = BaseDataFramType.config;
        this.param = param;
        this.data = data;
    }

    public ConfigDataFram() {
        this.type = BaseDataFramType.config;
    }


    public String createData(ConfigDataFram tagData) {
        if (tagData == null) {
            ToastUtils.showCenter("未获取配置");
            return "";
        }

        String data = tagData.getData();//返回的数据

        int position = data32;
        String hex = "";
        StringBuilder stringBuilder = new StringBuilder();
        //名称 转化hex
        hex = chinese2HexFormat(cGroupName, data32);//字符串32位
        stringBuilder.append(hex);
        LogUtil.d("字符串拼接的长度 = "+stringBuilder.length());
        //4 均质工作时间
        String s1 = int2HexFormat(iTimeWork, data4);
        stringBuilder.append(s1);
        LogUtil.d("均质工作时间 = " + s1);
        LogUtil.d("均质工作时间拼接的长度 = "+stringBuilder.length());
        position = position + data4;
        LogUtil.d("均质工作时间拼接的长度position  = "+position);

        //4 清水清洗时间
        String timewater = int2HexFormat(iTimeWater, data4);
        stringBuilder.append(timewater);
//        stringBuilder.append(subDataString(data, position, data4));
//        iTimeClear = parseIntResult(position, data4);
        LogUtil.d("清水清洗时间 = " + timewater);
        LogUtil.d("清水清洗时间 拼接的长度 = "+stringBuilder.length());
//        iTimeWater = parseIntResult(position, data4);
        position = position + data4;
        LogUtil.d("拼接的长度 = "+stringBuilder.length());
        //4 烘干时间 不配置
        stringBuilder.append(subDataString(data, position, data4));
//        stringBuilder.append(subDataString(data, position, data4));
//        iTimeClear = parseIntResult(position, data4);
        position = position + data4;
        //4 超声波清洗时间
        stringBuilder.append(int2HexFormat(iTimeSuper, data4));
//        iTimeSuper = parseIntResult(position, data4);
        position = position + data4;

        //2 磨位分段下降
        stringBuilder.append(int2HexFormat(cCountWork, data2));
//        cCountWork = parseIntResult(position, data2);
        position = position + data2;
        //2 清水位甩干次数
        stringBuilder.append(int2HexFormat(cCountWater, data2));
//        cCountWater = parseIntResult(position, data2);
        position = position + data2;
        //2 烘干位甩干次数
        stringBuilder.append(int2HexFormat(cCountClear, data2));
//        cCountClear = parseIntResult(position, data2);
        position = position + data2;
        //2 超声波位甩干次数
        stringBuilder.append(int2HexFormat(cCountSuper, data2));
//        cCountSuper = parseIntResult(position, data2);
        position = position + data2;

        //4 加入时间 清水槽
        stringBuilder.append(subDataString(data, position, data4));
//        iInWater = parseIntResult(position, data4);
        position = position + data4;

        //4 加入时间 洗剂槽
        stringBuilder.append(int2HexFormat(iInClear, data4));
//        iInClear = parseIntResult(position, data4);
        position = position + data4;

        //4 加入时间 超声槽 超声波槽清洗剂加入时间
        stringBuilder.append(subDataString(data, position, data4));
//        iInSuper = parseIntResult(position, data4);
        position = position + data4;

        //4 清洗槽排出时间
        stringBuilder.append(subDataString(data, position, data4));
//        iOutWater = parseIntResult(position, data4);
        position = position + data4;
        //4 溶剂槽排出时间
        stringBuilder.append(subDataString(data, position, data4));
//        iOutClear = parseIntResult(position, data4);
        position = position + data4;
        //4 超声波槽排出时间
        stringBuilder.append(subDataString(data, position, data4));
//        iOutSuper = parseIntResult(position, data4);
        position = position + data4;

        //2 bit0 = 1，工作位刀头浮动。0=不浮动。
        stringBuilder.append(int2HexFormat(cClrMode, data2));
//        stringBuilder.append(subDataString(data, position, data2));
//        cClrMode = parseIntResult(position, data2);
        position = position + data2;
        LogUtil.d("清洗模式工作模式 = " + cClrMode);
        //2 清洗位选项 清洗位置选择
        /**
         * [41]: (unsigned char) 清洗选择位
         * bit0 = 1，清水清洗位选择。
         * bit1 = 1，烘干清洗位选择。
         * Bit2 = 1，超声波清洗位选择。必选
         * bit3~7 保留
         */
        stringBuilder.append(int2HexFormat(cClrSelect, data2));
//        cClrSelect = parseIntResult(position, data2);
        position = position + data2;

        /**
         * [42]: 保留
         * [43]: 保留
         */
        stringBuilder.append(subDataString(data, position, data2));
//        cRFUA = parseIntResult(position, data2);
        position = position + data2;
        stringBuilder.append(subDataString(data, position, data2));
//        cRFUA = parseIntResult(position, data2);
        position = position + data2;
//            int iMotorSpeed;   // 均质工作电机速度
//            int iMotorBackSpeed;  // 均质工作电机返回速度
//            int iWorkFlwTime;  // 工作位浮动间隔时间
//            int iSuperMotT;   // 超声位电机转动时间
//            int iSuperFlwT;   // 超声位浮动间隔时间
//            int iRFUB;
        String s2 = int2HexFormat(iMotorSpeed, data4);
        LogUtil.d("转速刀头 = " + s2);
        stringBuilder.append(s2);
//        stringBuilder.append(subDataString(data, position, data4));
//        iMotorSpeed = parseIntResult(position, data4);
        position = position + data4;
//        iMotorBackSpeed = parseIntResult(position, data4);
        stringBuilder.append(subDataString(data, position, data4));
        position = position + data4;
//        iWorkFlwTime = parseIntResult(position, data4);
        stringBuilder.append(subDataString(data, position,  data4));
        position = position + data4;
//        iSuperMotT = parseIntResult(position, data4);
        stringBuilder.append(subDataString(data, position, data4));
        position = position + data4;
//        iSuperFlwT = parseIntResult(position, data4);
        stringBuilder.append(subDataString(data, position, data4));
        position = position + data4;

//        cRFUA = parseIntResult(position, data4);
        stringBuilder.append(subDataString(data, position, data2));
        position = position + data2;
//        cRFUA = parseIntResult(position, data2);
        position = position + data2;

        LogUtil.d("发送的数据stringBuilder = " + stringBuilder.toString());
        this.data = stringBuilder.toString();
        final String sendData = getSendData();
        return sendData;
    }

    @Override
    public void parseFrame(String frame) {
        super.parseFrame(frame);
        int position = 0;
        //具体解析

            LogUtil.d("解析数据:" + data);
            //32  字符
            position = position + data32;
            hexGroupName = data.substring(0, position);
            String temp = hexStr2Str(hexGroupName.toUpperCase());//转成大写
//            String work = str2HexStr("工作组2");
//            LogUtil.d("汉字转hex : " + work);
            cGroupName = CharUtils.getLetterAndChinese(temp);
            LogUtil.d("汉字 :" + cGroupName);
            //4 均质工作时间
            iTimeWork = parseIntResult(position, data4);
            position = position + data4;
            //4 清水清洗时间
            iTimeWater = parseIntResult(position, data4);
            position = position + data4;
            //4 烘干时间
            iTimeClear = parseIntResult(position, data4);
            position = position + data4;
            //4 超声波清洗时间
            iTimeSuper = parseIntResult(position, data4);
            position = position + data4;

            //2  研磨位分段下降
            cCountWork = parseIntResult(position, data2);
            position = position + data2;
            //2 清水位甩干次数
            cCountWater = parseIntResult(position, data2);
            position = position + data2;
            //2 烘干位甩干次数
            cCountClear = parseIntResult(position, data2);
            position = position + data2;
            //2 超声波位甩干次数
            cCountSuper = parseIntResult(position, data2);
            position = position + data2;

            //4 加入时间 清水槽
            iInWater = parseIntResult(position, data4);
            position = position + data4;

            //4 加入时间 洗剂槽
            iInClear = parseIntResult(position, data4);
            position = position + data4;

            //4 加入时间 超声槽 超声波槽清洗剂加入时间
            iInSuper = parseIntResult(position, data4);
            position = position + data4;

            //4 清洗槽排出时间
            iOutWater = parseIntResult(position, data4);
            position = position + data4;
            //4 溶剂槽排出时间
            iOutClear = parseIntResult(position, data4);
            position = position + data4;
            //4 超声波槽排出时间
            iOutSuper = parseIntResult(position, data4);
            position = position + data4;

            //2 清洗模式
            cClrMode = parseIntResult(position, data2);
            position = position + data2;
            LogUtil.d("清洗模式工作模式 = " + cClrMode);
            //2 清洗位选项 清洗位置选择
            /**
             * [41]: (unsigned char) 清洗选择位
             * bit0 = 1，清水清洗位选择。
             * bit1 = 1，烘干清洗位选择。
             * Bit2 = 1，超声波清洗位选择。必选
             * bit3~7 保留
             */
            cClrSelect = parseIntResult(position, data2);
            position = position + data2;

            /**
             * [42]: 保留
             * [43]: 保留
             */
            cRFUA = parseIntResult(position, data2);
            position = position + data2;
            cRFUA = parseIntResult(position, data2);
            position = position + data2;

//            int iMotorSpeed;   // 均质工作电机速度
//            int iMotorBackSpeed;  // 均质工作电机返回速度
//            int iWorkFlwTime;  // 工作位浮动间隔时间
//            int iSuperMotT;   // 超声位电机转动时间
//            int iSuperFlwT;   // 超声位浮动间隔时间
//            int iRFUB;
            iMotorSpeed = parseIntResult(position, data4);
            position = position + data4;
            iMotorBackSpeed = parseIntResult(position, data4);
            position = position + data4;
            iWorkFlwTime = parseIntResult(position, data4);
            position = position + data4;
            iSuperMotT = parseIntResult(position, data4);
            position = position + data4;
            iSuperFlwT = parseIntResult(position, data4);
            position = position + data4;

            cRFUA = parseIntResult(position, data4);
            position = position + data2;
            cRFUA = parseIntResult(position, data2);
            position = position + data4;

            LogUtil.d(toString());

    }


    /*是否转刀浮动*/
    public String getcClrModeHome() {
        if (cClrMode==1){
            return "   浮动";
        }else {
            return "";
        }
    }
    /*是否烘干*/
    public String getcClrSelectHome() {
        if (cClrSelect==7){
            return "    烘干";
        }else {
            return "";
        }
    }
    /*是否添加清洗剂*/
    public String getInClearHome() {
        if (cCountClear==1){
            return "   清洗剂";
        }else {
            return "";
        }
    }




    public int getStyleType() {
        return styleType;
    }

    public void setStyleType(int styleType) {
        this.styleType = styleType;
    }

    public String getcGroupName() {
        return cGroupName;
    }

    public void setcGroupName(String cGroupName) {
        this.cGroupName = cGroupName;
    }

    public String getHexGroupName() {
        return hexGroupName;
    }

    public void setHexGroupName(String hexGroupName) {
        this.hexGroupName = hexGroupName;
    }

    public int getiTimeWork() {
        return iTimeWork;
    }

    public void setiTimeWork(int iTimeWork) {
        this.iTimeWork = iTimeWork;
    }

    public int getiTimeWater() {
        return iTimeWater;
    }

    public void setiTimeWater(int iTimeWater) {
        this.iTimeWater = iTimeWater;
    }

    public int getiTimeClear() {
        return iTimeClear;
    }

    public void setiTimeClear(int iTimeClear) {
        this.iTimeClear = iTimeClear;
    }

    public int getiTimeSuper() {
        return iTimeSuper;
    }

    public void setiTimeSuper(int iTimeSuper) {
        this.iTimeSuper = iTimeSuper;
    }

    public int getcCountWork() {
        return cCountWork;
    }

    public void setcCountWork(int cCountWork) {
        this.cCountWork = cCountWork;
    }

    public int getcCountWater() {
        return cCountWater;
    }

    public void setcCountWater(int cCountWater) {
        this.cCountWater = cCountWater;
    }

    public int getcCountClear() {
        return cCountClear;
    }

    public void setcCountClear(int cCountClear) {
        this.cCountClear = cCountClear;
    }

    public int getcCountSuper() {
        return cCountSuper;
    }

    public void setcCountSuper(int cCountSuper) {
        this.cCountSuper = cCountSuper;
    }

    public int getiInWater() {
        return iInWater;
    }

    public void setiInWater(int iInWater) {
        this.iInWater = iInWater;
    }

    public int getiInClear() {
        return iInClear;
    }

    public void setiInClear(int iInClear) {
        this.iInClear = iInClear;
    }

//    public int getiInSuper_clear() {
//        return iInSuper_clear;
//    }
//
//    public void setiInSuper_clear(int iInSuper_clear) {
//        this.iInSuper_clear = iInSuper_clear;
//    }

    public int getiInSuper() {
        return iInSuper;
    }

    public void setiInSuper(int iInSuper) {
        this.iInSuper = iInSuper;
    }

    public int getiOutWater() {
        return iOutWater;
    }

    public void setiOutWater(int iOutWater) {
        this.iOutWater = iOutWater;
    }

    public int getiOutClear() {
        return iOutClear;
    }

    public void setiOutClear(int iOutClear) {
        this.iOutClear = iOutClear;
    }

    public int getiOutSuper() {
        return iOutSuper;
    }

    public void setiOutSuper(int iOutSuper) {
        this.iOutSuper = iOutSuper;
    }

    public int getcClrSelect() {
        return cClrSelect;
    }

    public void setcClrSelect(int cClrSelect) {
        this.cClrSelect = cClrSelect;
    }

    public int getcClrMode() {
        return cClrMode;
    }

    public void setcClrMode(int cClrMode) {
        this.cClrMode = cClrMode;
    }

    public int getcRFUA() {
        return cRFUA;
    }

    public void setcRFUA(int cRFUA) {
        this.cRFUA = cRFUA;
    }

    public int getiMotorSpeed() {
        return iMotorSpeed;
    }

    public void setiMotorSpeed(int iMotorSpeed) {
        this.iMotorSpeed = iMotorSpeed;
    }

    public int getiMotorBackSpeed() {
        return iMotorBackSpeed;
    }

    public void setiMotorBackSpeed(int iMotorBackSpeed) {
        this.iMotorBackSpeed = iMotorBackSpeed;
    }

    public int getiWorkFlwTime() {
        return iWorkFlwTime;
    }

    public void setiWorkFlwTime(int iWorkFlwTime) {
        this.iWorkFlwTime = iWorkFlwTime;
    }

    public int getiSuperMotT() {
        return iSuperMotT;
    }

    public void setiSuperMotT(int iSuperMotT) {
        this.iSuperMotT = iSuperMotT;
    }

    public int getiSuperFlwT() {
        return iSuperFlwT;
    }

    public void setiSuperFlwT(int iSuperFlwT) {
        this.iSuperFlwT = iSuperFlwT;
    }

    public int getiRFUB() {
        return iRFUB;
    }

    public void setiRFUB(int iRFUB) {
        this.iRFUB = iRFUB;
    }

    @Override
    public String toString() {
        return "ConfigDataFram{" +
                "cGroupName='" + cGroupName + '\'' +
                ", hexGroupName='" + hexGroupName + '\'' +
                ", iTimeWork=" + iTimeWork +
                ", iTimeWater=" + iTimeWater +
                ", iTimeClear=" + iTimeClear +
                ", iTimeSuper=" + iTimeSuper +
                ", cCountWork=" + cCountWork +
                ", cCountWater=" + cCountWater +
                ", cCountClear=" + cCountClear +
                ", cCountSuper=" + cCountSuper +
                ", iInWater=" + iInWater +
                ", iInClear=" + iInClear +
//                ", iInSuper_clear=" + iInSuper_clear +
                ", iInSuper=" + iInSuper +
                ", iOutWater=" + iOutWater +
                ", iOutClear=" + iOutClear +
                ", iOutSuper=" + iOutSuper +
                ", cClrSelect=" + cClrSelect +
                ", cClrMode=" + cClrMode +
                ", cRFUA=" + cRFUA +
                ", iMotorSpeed=" + iMotorSpeed +
                ", iMotorBackSpeed=" + iMotorBackSpeed +
                ", iWorkFlwTime=" + iWorkFlwTime +
                ", iSuperMotT=" + iSuperMotT +
                ", iSuperFlwT=" + iSuperFlwT +
                ", iRFUB=" + iRFUB +
                '}';
    }
}
